home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DJGPP / DJ111M2.ZIP / docs / djgpp / libc-t-z.tex < prev    next >
Text File  |  1994-01-08  |  17KB  |  820 lines

  1. @c ----------------------------------------------------------------------
  2. @node tell, telldir, system, Alphabetical List
  3.  
  4. @heading @code{tell}
  5. @subheading Syntax
  6.  
  7. @example
  8. long tell(int file);
  9. @end example
  10.  
  11. @subheading Description
  12.  
  13. This function returns the location of the file pointer for @var{file}. 
  14.  
  15. @subheading Return Value
  16.  
  17. The file pointer, or -1 on error.
  18.  
  19. @subheading Example
  20.  
  21. @example
  22. long q = tell(fd);
  23. @end example
  24.  
  25. @c ----------------------------------------------------------------------
  26. @node telldir, tempnam, tell, Alphabetical List
  27.  
  28. @heading @code{telldir}
  29. @subheading Syntax
  30.  
  31. @example
  32. #include <dirent.h>
  33.  
  34. long telldir(DIR *dir);
  35. @end example
  36.  
  37. @subheading Description
  38.  
  39. This function returns a value which indicates the position of the
  40. pointer in the given directory.  This value is only useful as an
  41. argument to @code{seekdir} (@xref{seekdir}). 
  42.  
  43. @subheading Return Value
  44.  
  45. The directory pointer.
  46.  
  47. @subheading Example
  48.  
  49. @example
  50. DIR *dir;
  51. long q = telldir(dir);
  52. do_something();
  53. seekdir(dir, q);
  54. @end example
  55.  
  56. @c ----------------------------------------------------------------------
  57. @node tempnam, time, telldir, Alphabetical List
  58.  
  59. @heading @code{tempnam}
  60. @subheading Syntax
  61.  
  62. @example
  63. #include <stdio.h>
  64.  
  65. char *tempnam(const char *dir, const char *prefix);
  66. @end example
  67.  
  68. @subheading Description
  69.  
  70. This function returns a temporary file name in a buffer allocated by
  71. @code{malloc}.  The locations and filenames searched for temporary space
  72. are as follows:
  73.  
  74. @example
  75. getenv("TMPDIR")/@var{prefix}??????
  76. @var{dir}/@var{prefix}??????
  77. @code{P_tmpdir}/@var{prefix}??????
  78. /tmp/@var{prefix}??????
  79. @end example
  80.  
  81. @subheading Return Value
  82.  
  83. A pointer to the file name, or NULL if error.
  84.  
  85. @subheading Example
  86.  
  87. @example
  88. char *fn = tempnam(".", "dj");
  89. free(fn);
  90. @end example
  91.  
  92. @c ----------------------------------------------------------------------
  93. @node time, timezone, tempnam, Alphabetical List
  94.  
  95. @heading @code{time}
  96. @subheading Syntax
  97.  
  98. @example
  99. #include <time.h>
  100.  
  101. time_t time(time_t *t);
  102. @end example
  103.  
  104. @subheading Description
  105.  
  106. If @var{t} is not @code{NULL}, the current time is stored in @code{*t}. 
  107.  
  108. @subheading Return Value
  109.  
  110. The current time is returned.
  111.  
  112. @subheading Example
  113.  
  114. @example
  115. printf("Time is %d\n", time(0));
  116. @end example
  117.  
  118. @c ----------------------------------------------------------------------
  119. @node timezone, tmpfile, time, Alphabetical List
  120.  
  121. @heading @code{timezone}
  122. @subheading Syntax
  123.  
  124. @example
  125. #include <time.h>
  126.  
  127. char *timezone(int minutes, int daylight);
  128. @end example
  129.  
  130. @subheading Description
  131.  
  132. Given the number of minutes west of GMT and whether or not daylight
  133. savings time is in affect, returns the name of the timezone. 
  134.  
  135. If the environment variable TZNAME is set, it should be like
  136. @code{EST,EDT}, and the name of the timezone will come from that. 
  137.  
  138. @subheading Return Value
  139.  
  140. A pointer to the timezone or @code{NULL} if invalid.
  141.  
  142. @subheading Example
  143.  
  144. @example
  145. printf("EST ? %s\n", timezone(5*60, 0));
  146. @end example
  147.  
  148. @c ----------------------------------------------------------------------
  149. @node tmpfile, tmpnam, timezone, Alphabetical List
  150.  
  151. @heading @code{tmpfile}
  152. @subheading Syntax
  153.  
  154. @example
  155. #include <stdio.h>
  156.  
  157. FILE *tmpfile(void);
  158. @end example
  159.  
  160. @subheading Description
  161.  
  162. This function opens a temporary file.  It will automatically be removed
  163. when the program exits. 
  164.  
  165. @subheading Return Value
  166.  
  167. A newly opened file.
  168.  
  169. @subheading Example
  170.  
  171. @example
  172. FILE *tmp = tmpfile();
  173. @end example
  174.  
  175. @c ----------------------------------------------------------------------
  176. @node tmpnam, tolower, tmpfile, Alphabetical List
  177.  
  178. @heading @code{tmpnam}
  179. @subheading Syntax
  180.  
  181. @example
  182. #include <stdio.h>
  183.  
  184. char *tmpnam(char *s);
  185. @end example
  186.  
  187. @subheading Description
  188.  
  189. If @var{s} is NULL, a buffer is allocated, else @var{s} is used to hold
  190. the name of a unique file. 
  191.  
  192. @subheading Return Value
  193.  
  194. A pointer to the new file name.
  195.  
  196. @subheading Example
  197.  
  198. @example
  199. char buf[PATH_MAX];
  200. char *s = tmpname(buf);
  201. @end example
  202.  
  203. @c ----------------------------------------------------------------------
  204. @node tolower, toupper, tmpnam, Alphabetical List
  205.  
  206. @heading @code{tolower}
  207. @subheading Syntax
  208.  
  209. @example
  210. #include <ctype.h>
  211.  
  212. int tolower(int c);
  213. @end example
  214.  
  215. @subheading Description
  216.  
  217. This function returns @var{c}, converting it to lower case if it is
  218. upper case.  @xref{toupper}
  219.  
  220. @subheading Return Value
  221.  
  222. The upper case letter.
  223.  
  224. @subheading Example
  225.  
  226. @example
  227. for (i=0; buf[i]; i++)
  228.   buf[i] = tolower(buf[i]);
  229. @end example
  230.  
  231. @c ----------------------------------------------------------------------
  232. @node toupper, truncate, tolower, Alphabetical List
  233.  
  234. @heading @code{toupper}
  235. @subheading Syntax
  236.  
  237. @example
  238. #include <ctype.h>
  239.  
  240. int toupper(int c);
  241. @end example
  242.  
  243. @subheading Description
  244.  
  245. This function returns @var{c}, converting it to upper case if it is
  246. lower case. @xref{tolower}
  247.  
  248. @subheading Return Value
  249.  
  250. The upper case letter.
  251.  
  252. @subheading Example
  253.  
  254. @example
  255. for (i=0; buf[i]; i++)
  256.   buf[i] = toupper(buf[i]);
  257. @end example
  258.  
  259. @c ----------------------------------------------------------------------
  260. @node truncate, ttyname, toupper, Alphabetical List
  261.  
  262. @heading @code{truncate}
  263. @subheading Syntax
  264.  
  265. @example
  266. #include <osfcn.h>
  267.  
  268. int truncate(const char *file, unsigned long size);
  269. @end example
  270.  
  271. @subheading Description
  272.  
  273. This function truncates @var{file} to @var{size} bytes.
  274.  
  275. @subheading Return Value
  276.  
  277. Zero on success, nonzero on failure.
  278.  
  279. @subheading Example
  280.  
  281. @example
  282. ftruncate("/tmp/data.txt", 400);
  283. @end example
  284.  
  285. @c ----------------------------------------------------------------------
  286. @node ttyname, tzname, truncate, Alphabetical List
  287.  
  288. @heading @code{ttyname}
  289. @subheading Syntax
  290.  
  291. @example
  292. #include <osfcn.h>
  293.  
  294. char *ttyname(int file);
  295. @end example
  296.  
  297. @subheading Description
  298.  
  299. Gives the name of the terminal associated with @var{file}. 
  300.  
  301. @subheading Return Value
  302.  
  303. Returns "/dev/con" if @var{file} is a device, else @code{NULL}.
  304.  
  305. @subheading Example
  306.  
  307. @example
  308. char *tty = ttyname(0);
  309. @end example
  310.  
  311. @c ----------------------------------------------------------------------
  312. @node tzname, tzset, ttyname, Alphabetical List
  313.  
  314. @heading @code{tzname}
  315. @subheading Syntax
  316.  
  317. @example
  318. extern char *tzname[2]
  319. @end example
  320.  
  321. @subheading Description
  322.  
  323. This array holds the names of standard and daylight savings timezones
  324. for the local area.  You must call @code{tzset} to initialize these.
  325.  
  326. @c ----------------------------------------------------------------------
  327. @node tzset, tzsetwall, tzname, Alphabetical List
  328.  
  329. @heading @code{tzset}
  330. @subheading Syntax
  331.  
  332. @example
  333. #include <time.h>
  334.  
  335. void tzset(void);
  336. @end example
  337.  
  338. @subheading Description
  339.  
  340. This function initializes the timezone information.
  341.  
  342. @subheading Return Value
  343.  
  344. None.
  345.  
  346. @c ----------------------------------------------------------------------
  347. @node tzsetwall, _tztab, tzset, Alphabetical List
  348.  
  349. @heading @code{tzsetwall}
  350. @subheading Syntax
  351.  
  352. @example
  353. #include <time.h>
  354.  
  355. void tzsetwall(void)
  356. @end example
  357.  
  358. @subheading Description
  359.  
  360. This function initializes the system to "wall clock" time. 
  361.  
  362. @subheading Return Value
  363.  
  364. None.
  365.  
  366. @c ----------------------------------------------------------------------
  367. @node _tztab, umask, tzsetwall, Alphabetical List
  368.  
  369. @heading @code{_tztab}
  370.  
  371. @subheading Description
  372.  
  373. This is an internal variable used by the @code{tz} functions. 
  374.  
  375. @c ----------------------------------------------------------------------
  376. @node umask, ungetc, _tztab, Alphabetical List
  377.  
  378. @heading @code{umask}
  379.  
  380. @subheading Description
  381.  
  382. This is an internal function used by gcc to help perform certain
  383. operations. 
  384.  
  385. @c ----------------------------------------------------------------------
  386. @node ungetc, unlink, umask, Alphabetical List
  387.  
  388. @heading @code{ungetc}
  389. @subheading Syntax
  390.  
  391. @example
  392. #include <stdio.h>
  393.  
  394. int ungetc(int c, FILE *file);
  395. @end example
  396.  
  397. @subheading Description
  398.  
  399. This function pushes @var{c} back into the @var{file}.  You can only
  400. push back one character at a time. 
  401.  
  402. @subheading Return Value
  403.  
  404. The pushed-back character, or @code{EOF} on error.
  405.  
  406. @subheading Example
  407.  
  408. @example
  409. int q;
  410. while (q = getc(stdin) != 'q');
  411. ungetc(q);
  412. @end example
  413.  
  414. @c ----------------------------------------------------------------------
  415. @node unlink, unlock, ungetc, Alphabetical List
  416.  
  417. @heading @code{unlink}
  418. @subheading Syntax
  419.  
  420. @example
  421. #include <osfcn.h>
  422.  
  423. int unlink(const char *file);
  424. @end example
  425.  
  426. @subheading Description
  427.  
  428. This function removes a file from the file system. 
  429.  
  430. @subheading Return Value
  431.  
  432. Zero on success, nonzero on failure. 
  433.  
  434. @subheading Example
  435.  
  436. @example
  437. unlink("data.txt");
  438. @end example
  439.  
  440. @c ----------------------------------------------------------------------
  441. @node unlock, unsetenv, unlink, Alphabetical List
  442.  
  443. @heading @code{unlock}
  444. @subheading Syntax
  445.  
  446. @example
  447. #include <io.h>
  448.  
  449. int unlock(int fd, long offset, long length);
  450. @end example
  451.  
  452. @subheading Description
  453. Unlocks a region previously locked by @code{lock}.
  454.  
  455. @xref{lock}.
  456.  
  457. @subheading Return Value
  458. Zero if successful, nonzero if not.
  459.  
  460. @c ----------------------------------------------------------------------
  461. @node unsetenv, usleep, unlock, Alphabetical List
  462.  
  463. @heading @code{unsetenv}
  464. @subheading Syntax
  465.  
  466. @example
  467. #include <stdlib.h>
  468.  
  469. void unsetenv(const char *name);
  470. @end example
  471.  
  472. @subheading Description
  473.  
  474. This function removes the given environment variable from the
  475. environment. 
  476.  
  477. @subheading Return Value
  478.  
  479. None.
  480.  
  481. @subheading Example
  482.  
  483. @example
  484. unsetenv("TERM");
  485. @end example
  486.  
  487. @c ----------------------------------------------------------------------
  488. @node usleep, utime, unsetenv, Alphabetical List
  489.  
  490. @heading @code{usleep}
  491. @subheading Syntax
  492.  
  493. @example
  494. #include <osfcn.h>
  495.  
  496. unsigned usleep(unsigned usec);
  497. @end example
  498.  
  499. @subheading Description
  500.  
  501. This function pauses the program for @var{usec} microseconds. 
  502.  
  503. @subheading Return Value
  504.  
  505. The number of unsleept microseconds (i.e. zero).
  506.  
  507. @subheading Example
  508.  
  509. @example
  510. usleep(500000);
  511. @end example
  512.  
  513. @c ----------------------------------------------------------------------
  514. @node utime, utimes, usleep, Alphabetical List
  515.  
  516. @heading @code{utime}
  517. @subheading Syntax
  518.  
  519. @example
  520. #include <utime.h>
  521.  
  522. itn utime(const char *file, const struct utimbuf *time);
  523. @end example
  524.  
  525. @subheading Description
  526.  
  527. This function sets the modification timestamp on the @var{file}.  The
  528. new time is stored in this structure:
  529.  
  530. @example
  531. struct utimbuf
  532. @{
  533.     time_t  actime;  /* access time (unused) */
  534.     time_t  modtime; /* modification time */
  535. @};
  536. @end example
  537.  
  538. @subheading Return Value
  539.  
  540. Zero for success, nonzero for failure.
  541.  
  542. @subheading Example
  543.  
  544. @example
  545. struct utimbuf t;
  546. t.modtime = time(0);
  547. utime("data.txt", &t);
  548. @end example
  549.  
  550. @c ----------------------------------------------------------------------
  551. @node utimes, valloc, utime, Alphabetical List
  552.  
  553. @heading @code{utimes}
  554. @subheading Syntax
  555.  
  556. @example
  557. int utimes(const char *file, struct timevar tvp[2]);
  558. @end example
  559.  
  560. @subheading Description
  561.  
  562. This function does nothing.  It is provided to assist in
  563. porting Unix programs.
  564.  
  565. @subheading Return Value
  566.  
  567. Zero for success, nonzero for failure.
  568.  
  569. @c ----------------------------------------------------------------------
  570. @node valloc, vfork, utimes, Alphabetical List
  571.  
  572. @heading @code{valloc}
  573. @subheading Syntax
  574.  
  575. @example
  576. #include <stdlib.h>
  577.  
  578. void *valloc(unsigned size);
  579. @end example
  580.  
  581. @subheading Description
  582.  
  583. This function is just like @code{malloc} (@xref{malloc}) except that the
  584. returned pointer is always aligned to a CPU page boundary.  This
  585. alignment is rarely useful in djgpp. 
  586.  
  587. @subheading Return Value
  588.  
  589. A pointer to a newly allocated block of memory. 
  590.  
  591. @subheading Example
  592.  
  593. @example
  594. char *page = valloc(getpagesize());
  595. @end example
  596.  
  597. @c ----------------------------------------------------------------------
  598. @node vfork, vfprintf, valloc, Alphabetical List
  599.  
  600. @heading @code{vfork}
  601.  
  602. @subheading Description
  603.  
  604. This function is provided to assist in porting Unix programs only.  It
  605. always fails. 
  606.  
  607. @subheading Return Value
  608.  
  609. -1
  610.  
  611. @c ----------------------------------------------------------------------
  612. @node vfprintf, vprintf, vfork, Alphabetical List
  613.  
  614. @heading @code{vfprintf}
  615. @subheading Syntax
  616.  
  617. @example
  618. #include <stdio.h>
  619. #include <stdarg.h>
  620.  
  621. int vfprintf(FILE *file, const char *format, va_list arguments);
  622. @end example
  623.  
  624. @subheading Description
  625.  
  626. Sends formatted output from the @var{arguments} to the @var{file}. 
  627. @xref{printf}
  628.  
  629. @subheading Return Value
  630.  
  631. The number of characters written.
  632.  
  633. @c ----------------------------------------------------------------------
  634. @node vprintf, vsprintf, vfprintf, Alphabetical List
  635.  
  636. @heading @code{vprintf}
  637. @subheading Syntax
  638.  
  639. @example
  640. #include <stdio.h>
  641. #include <stdarg.h>
  642.  
  643. int vprintf(const char *format, va_list arguments);
  644. @end example
  645.  
  646. @subheading Description
  647.  
  648. Sends formatted output from the @var{arguments} to @code{stdout}. 
  649. @xref{printf}
  650.  
  651. @subheading Return Value
  652.  
  653. The number of characters written.
  654.  
  655. @c ----------------------------------------------------------------------
  656. @node vsprintf, wait, vprintf, Alphabetical List
  657.  
  658. @heading @code{vsprintf}
  659. @subheading Syntax
  660.  
  661. @example
  662. #include <stdio.h>
  663. #include <stdarg.h>
  664.  
  665. int vsprintf(char *buffer, const char *format, va_list arguments);
  666. @end example
  667.  
  668. @subheading Description
  669.  
  670. Sends formatted output from the @var{arguments} to the @var{buffer}.
  671. @xref{printf}
  672.  
  673. @subheading Return Value
  674.  
  675. The number of characters written.
  676.  
  677. @c ----------------------------------------------------------------------
  678. @node wait, write, vsprintf, Alphabetical List
  679.  
  680. @heading @code{wait}
  681.  
  682. @subheading Description
  683.  
  684. This function is provided only to assist in porting from Unix.  It
  685. always returns an error condition. 
  686.  
  687. @c ----------------------------------------------------------------------
  688. @node write, writecr, wait, Alphabetical List
  689.  
  690. @heading @code{write}
  691. @subheading Syntax
  692.  
  693. @example
  694. #include <osfcn.h>
  695.  
  696. int write(int file, const void *buffer, unsigned count);
  697. @end example
  698.  
  699. @subheading Description
  700.  
  701. This function writes @var{count} bytes from @var{buffer} to @var{file}. 
  702. It returns the number of bytes actually written.  It will return zero at
  703. end-of-file, and may return less than @var{count} even under valid
  704. conditions. 
  705.  
  706. Note that if @var{file} is a text file, @code{write} may write more
  707. bytes than it reports. 
  708.  
  709. @subheading Return Value
  710.  
  711. The number of bytes written, zero at EOF, or -1 on error.
  712.  
  713. @subheading Example
  714.  
  715. @example
  716. write(fd, "hello", 5);
  717. @end example
  718.  
  719. @c ----------------------------------------------------------------------
  720. @node writecr, writev, write, Alphabetical List
  721.  
  722. @heading @code{writecr}
  723. @subheading Syntax
  724.  
  725. @example
  726. int write(int file, const void *buffer, unsigned count);
  727. @end example
  728.  
  729. @subheading Description
  730.  
  731. This is just like @code{write} (@xref{write}) except that the Ctrl-M
  732. characters are inserted before each Ctrl-J character to convert from
  733. Unix-style text lines to DOS-style text lines when writing to a binary
  734. file. 
  735.  
  736. @subheading Return Value
  737.  
  738. The number of bytes written, zero at EOF, or -1 on error.
  739.  
  740. @subheading Example
  741.  
  742. @example
  743. writecr(fd, "hello\n", 6);
  744. @end example
  745.  
  746. @c ----------------------------------------------------------------------
  747. @node writev, xmalloc, writecr, Alphabetical List
  748.  
  749. @heading @code{writev}
  750. @subheading Syntax
  751.  
  752. @example
  753. #include <sys/uio.h>
  754.  
  755. int writev(int handle, struct iovec *iov, int count);
  756. @end example
  757.  
  758. @subheading Description
  759.  
  760. This is just like @code{readv} (@xref{readv}), except that it writes
  761. instead of reading. 
  762.  
  763. @subheading Return Value
  764.  
  765. The number of bytes written.
  766.  
  767. @c ----------------------------------------------------------------------
  768. @node xmalloc, xrealloc, writev, Alphabetical List
  769.  
  770. @heading @code{xmalloc}
  771. @subheading Syntax
  772.  
  773. @example
  774. void *xmalloc(size_t size);
  775. @end example
  776.  
  777. @subheading Description
  778.  
  779. This function is just like @code{malloc} (@xref{malloc}), except that if
  780. there is no more memory, it prints an error message and exits. 
  781.  
  782. @subheading Return Value
  783.  
  784. A pointer to the newly allocated memory.
  785.  
  786. @subheading Example
  787.  
  788. @example
  789. char *f = xmalloc(100);
  790. @end example
  791.  
  792. @c ----------------------------------------------------------------------
  793. @node xrealloc, , xmalloc, Alphabetical List
  794.  
  795. @heading @code{xrealloc}
  796. @subheading Syntax
  797.  
  798. @example
  799. void *xrealloc(void *ptr, size_t size);
  800. @end example
  801.  
  802. @subheading Description
  803.  
  804. This function is just like @code{realloc} (@xref{realloc}), except that
  805. if there is no more memory, it prints an error message and exits.  It
  806. can also properly handle @var{ptr} being @code{NULL}. 
  807.  
  808. @subheading Return Value
  809.  
  810. A pointer to a possibly new block.
  811.  
  812. @subheading Example
  813.  
  814. @example
  815. char *buf;
  816. buf = (char *)xrealloc(buf, new_size);
  817. @end example
  818.  
  819.  
  820.